

def look_money():
    global n, principal
    while 1:
        if principal < target:
            principal += principal * 0.05
            n += 1
            print(f"第{n}年的本金为{int(principal)}元,利息为{int(principal * 0.05)}元")
        else:
            print(f"一共需要{n}年才能获得目标金额！")
            break


while 1:
    principal = input("请输入你的本金：")
    target = input("请输入你的目标金额：")
    n = 0
    if principal.isdigit() and target.isdigit():
        principal = int(principal)
        target = int(target)
        if target < principal:
            print("请输入正确的金额！")
        else:
            look_money()
            break
    else:
        print("请输入正确的金额！！")
